package org.sparkle.db.basic;

import java.util.List;

import com.avaje.ebean.Ebean;

public class BaseServiceImpl<T> implements BaseService<T> {

	private Class _class;
	
	public BaseServiceImpl(Class _class) {
		this._class=_class;
	}
	
	/* (non-Javadoc)
	 * @see sparkle.db.BaseService#save(sparkle.db.BaseVO)
	 */
	@Override
	public void save(BaseVO bean) throws Exception{
		Ebean.save(bean);
	}
	
	/* (non-Javadoc)
	 * @see sparkle.db.BaseService#update(sparkle.db.BaseVO)
	 */
	@Override
	public void update(BaseVO bean){
		Ebean.save(bean);
	}
	
	/* (non-Javadoc)
	 * @see sparkle.db.BaseService#delete(sparkle.db.BaseVO)
	 */
	@Override
	public void delete(BaseVO bean){
		Ebean.delete(bean);
	}
	
	/* (non-Javadoc)
	 * @see sparkle.db.BaseService#all()
	 */
	@Override
	@SuppressWarnings("unchecked")
	public List<T> all(){
		return Ebean.find(_class).findList();
	}

	@Override
	public T getById(Object obj) {		
		return (T) Ebean.find(_class, obj);
	}
}
